package com.core.life.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.core.common.pageModel.EasyuiDataGridColumns;
import com.core.common.pageModel.EasyuiDataGridJson;
import com.core.life.service.IAccountingRelationsService;
import com.core.life.vo.ConsumeCountVo;

@Controller
@RequestMapping("admin/accountingRelations")
public class AccountingRelationsController {

	@Resource
	private IAccountingRelationsService accountingRelationsService;

	@RequestMapping("/index")
	public String index() {
		return "admin/accountingRelations/index";
	}
	
	@RequestMapping(value = "/getDataGridColumns.do")
	@ResponseBody
	public List<EasyuiDataGridColumns> getDataGridColumns(String ruleCatalogId) {
		return accountingRelationsService.getAccountingRelationsDataGridColumnList();
	}
	
	@RequestMapping(value = "/getList", method = RequestMethod.POST)
	@ResponseBody
	public EasyuiDataGridJson getList(HttpServletRequest request) {
		EasyuiDataGridJson json = new EasyuiDataGridJson();
		String strDate = request.getParameter("countDatetime");
		Map<String, Object> optionMap = new HashMap<String, Object>();
		optionMap.put("strDate", strDate);
		List<Map<String, Object>> list = accountingRelationsService.getAccountingRelationsList(optionMap);
		if(CollectionUtils.isNotEmpty(list)){
			json.setTotal((long)list.size());
			json.setRows(list);
		}
		if(null == json.getRows()){
			json.setTotal(0l);
			json.setRows(new ArrayList<ConsumeCountVo>());						
		}
		return json;			
	}
}
